﻿using AutoMapper;
using System;
using System.Collections.Generic;
using System.Text;
using TianShu.Data;
using TianShu.MultiTenancy;
using TianShu.TenantManagement.Dal.Abstracts.Entities;
using TianShu.TenantManagement.Dal.Abstracts.Etos;

namespace TianShu.TenantManagement.Dal.AutoMapperConfig
{
    public class TianShuTenantManagementDalMappingProfile: Profile
    {
        public TianShuTenantManagementDalMappingProfile()
        {
            CreateMap<TenantEntity, TenantConfiguration>()
                .ForMember(ti => ti.ConnectionStrings, opts =>
                {
                    opts.MapFrom((tenant, ti) =>
                    {
                        var connStrings = new ConnectionStrings();

                        foreach (var connectionString in tenant.ConnectionStrings)
                        {
                            connStrings[connectionString.Name] = connectionString.Value;
                        }

                        return connStrings;
                    });
                })
                .ForMember(x => x.IsActive, x => x.Ignore());

            CreateMap<TenantEntity, TenantEto>();
        }
    }
}
